package com.talentgame.tankspk.UIStage;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Event;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.talentgame.tankspk.GameCore.TanksGame;

/**
 * Created by 54560 on 2016/12/28.
 */
public class StartStage extends  BaseStage{
    Texture bgTexture;
    Texture buttonBg;
    Image bg;
    ImageButton playButton;
    public StartStage(AssetManager assets) {
        super(assets);
        bgTexture  =new Texture(Gdx.files.internal("ui/fengmian.png"));
        buttonBg = new Texture(Gdx.files.internal("ui/startbutton.png"));
        TextureRegion bgtr = new TextureRegion(bgTexture,bgTexture.getWidth(),bgTexture.getHeight());
        bg= new Image(bgtr);
        bg.setBounds(0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
        TextureRegionDrawable buttonUp = new TextureRegionDrawable(new TextureRegion(buttonBg));
        ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
        //style.imageUp = buttonUp;
        style.up = buttonUp;
        playButton = new ImageButton(style);
        playButton.setBounds(Gdx.graphics.getWidth()/2-playButton.getWidth(),200,300,300);
        playButton.addListener(new ClickListener(){
            @Override
            public void clicked(InputEvent event, float x, float y) {
                //避免重复按
                if(TanksGame.instance.gameState == TanksGame.GAME_Matching)
                {
                    Gdx.app.log("Ui","当前正在匹配中!,不能再次按开始");
                    return;
                }
                Gdx.app.log("Ui","点击了开始");
                TanksGame.instance.StartGame();
            }
        });
        addActor(bg);
        addActor(playButton);
    }
}
